package de.hatraco.funderberg.blackjack.views;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

import de.hatraco.funderberg.blackjack.data.DataMISC;
import de.hatraco.funderberg.blackjack.data.GraphicsBlackJack;
import de.hatraco.funderberg.blackjack.utils.MaxDoc;

public class NamesDialog extends JDialog {
	
	//Singleton Pattern: Stellt sicher, dass nur eine Instanz von NamesDialog existiert
	private static NamesDialog instance = new NamesDialog();

	public static NamesDialog getInstance() {
		if(instance == null) {
			instance = new NamesDialog();
		}
		return instance;
	}
	
	private JLabel bg_names;
	private JLabel names_player;
	private JLabel names_text1;
	private JLabel names_text2;
	
	private JTextField name_input;
	
	private JButton b_names_ok;
	private JButton b_names_startgame;
	
	private int count;
	
	//private String link = DataMISC.LINKIMG;
	
	private GraphicsBlackJack img;
	
	private NamesDialog() {
		
		//Instanziert GraphicsBlackJack (für die Bilder)
		this.img = GraphicsBlackJack.getInstance();
		
		//Legt die Größe des Fensters fest
		this.setSize(400,300);
		//Legt fest, dass die Größe nicht verändert werden kann
		this.setResizable(false);
		//Legt fest, dass das Fenster nicht über das "X" rechts oben geschlossen werden kann
		this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
		//Gibt dem Fenster ein BorderLayout
		this.setLayout(new BorderLayout());
		//Legt den Hintergrund fest		
		bg_names = new JLabel(img.getBgdialogdef());
		//Fügt den Hintergrund hinzu        
        this.add(bg_names);
        //Gibt dem Hintergrund ein "leeres" Layout
        bg_names.setLayout(null);
        
        //Instanziert, Modifiziert und Positioniert die Elemente
        //JLabels
        names_player = new JLabel("Player 1");
        names_player.setFont(DataMISC.ARIAL_BOLD20);
    	names_player.setForeground(Color.WHITE);
    	names_player.setBounds(0, 40, 400, 25);
    	names_player.setHorizontalAlignment(SwingConstants.CENTER);
    	
    	names_text1 = new JLabel("Please fill in your name:");
    	names_text1.setFont(DataMISC.ARIAL_BOLD20);
    	names_text1.setForeground(Color.WHITE);
    	names_text1.setBounds(0, 75, 400, 25);
    	names_text1.setHorizontalAlignment(SwingConstants.CENTER);
    	
    	names_text2 = new JLabel("(max. 10 signs)");
    	names_text2.setFont(DataMISC.ARIAL_BOLD20);
    	names_text2.setForeground(Color.WHITE);
    	names_text2.setBounds(0, 165, 400, 25);
    	names_text2.setHorizontalAlignment(SwingConstants.CENTER);
    	
    	//JTextField
    	name_input = new JTextField();
    	name_input.setFont(DataMISC.ARIAL_BOLD16);
    	name_input.setDocument(new MaxDoc(10));
    	name_input.setBounds(75, 120, 250, 35);
    	
    	//Buttons
    	b_names_ok = new JButton(img.getBtok());
    	b_names_startgame = new JButton(img.getBtstartgame());
    	
    	b_names_ok.setBounds(320, 220, 60, 40);
    	b_names_startgame.setBounds(260, 220, 120, 40);
    	
    	b_names_startgame.setVisible(false);
    	
    	//Fügt die Elemente dem Hintergrund hinzu
    	bg_names.add(names_player);
    	bg_names.add(names_text1);
    	bg_names.add(names_text2);
    	bg_names.add(name_input);
    	bg_names.add(b_names_ok);
    	bg_names.add(b_names_startgame);
    	
    	//Setzt count
    	count = 0;
    }
	
	//Definiert Listener für die Buttons
	public void setNamesListener(ActionListener ae) {
		this.b_names_ok.addActionListener(ae);
		this.b_names_startgame.addActionListener(ae);
	}

	public JButton getB_names_ok() {
		return b_names_ok;
	}

	public void setB_names_ok(JButton b_names_ok) {
		this.b_names_ok = b_names_ok;
	}

	public JButton getB_names_startgame() {
		return b_names_startgame;
	}

	public void setB_names_startgame(JButton b_names_startgame) {
		this.b_names_startgame = b_names_startgame;
	}

	public JLabel getNames_player() {
		return names_player;
	}

	public void setNames_player(JLabel names_player) {
		this.names_player = names_player;
	}

	public JTextField getName_input() {
		return name_input;
	}

	public void setName_input(JTextField name_input) {
		this.name_input = name_input;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}
}
